﻿using System.Collections.Generic;
using System.Text;

namespace tiny_compiler
{
	public class Cursor :
		IOperator
	{
		public Cursor(string _offsetValueName)
		{
			m_offsetValueName = _offsetValueName;
		}

		#region IOperator Members

		public int Length
		{
			get { return Compiler.NameLength + Compiler.LengthLength + Compiler.NumberLength; }
		}

		public string Name
		{
			get { return string.Empty; }
		}

		public void Resolve(IEnumerable<IOperator> _operators)
		{
			m_offsetValue = _operators.Offset(m_offsetValueName);
		}

		public void Append(StringBuilder _data)
		{
			_data.Append(Compiler.CursorName);
			_data.Append(CompilerUtility.ConvertLength(Length));
			_data.Append(CompilerUtility.ConvertNumber(m_offsetValue));
		}

		#endregion

		private string m_offsetValueName;
		private int m_offsetValue;
	}
}
